function displaySubMenu(li) { 
	var subMenu = li.getElementsByTagName("div")[0]; 
	subMenu.style.display = "block"; 
} 
function hideSubMenu(li) { 
	var subMenu = li.getElementsByTagName("div")[0]; 
	subMenu.style.display = "none"; 
}
(function( factory ) {
	if ( typeof define === "function" && define.amd ) {
		define( ["jquery", "../jquery.validate"], factory );
	} else {
		factory( jQuery );
	}
}(function( $ ) {

/*
 * Translated default messages for the jQuery validation plugin.
 * Locale: ZH (Chinese, 中文 (Zhōngwén), 汉语, 漢語)
 */
$.extend($.validator.messages, {
	required: "请填写该字段",
	remote: "请修正此字段",
	email: "请输入有效的电子邮件地址",
	url: "请输入有效的网址",
	date: "请输入有效的日期",
	dateISO: "请输入有效的日期 (YYYY-MM-DD)",
	number: "请输入有效的数字",
	digits: "只能输入数字",
	creditcard: "请输入有效的信用卡号码",
	equalTo: "你的输入不相同",
	extension: "请输入有效的后缀",
	maxlength: $.validator.format("最多可以输入 {0} 个字符"),
	minlength: $.validator.format("最少要输入 {0} 个字符"),
	rangelength: $.validator.format("请输入长度在 {0} 到 {1} 之间的字符串"),
	range: $.validator.format("请输入范围在 {0} 到 {1} 之间的数值"),
	max: $.validator.format("请输入不大于 {0} 的数值"),
	min: $.validator.format("请输入不小于 {0} 的数值")
});

}));

$().ready(function() {
    $("#commentForm").validate();
});
$.validator.setDefaults({
    submitHandler: function() {
      $("#commentForm").submit();
    }
});

$(function() {
  $("#searchbtn").click(function(){
  $("#if_csv").val(0);
  });
});

$(document).ready(function(){
jQuery.hoverPlugin={
	hover:function(selector){
$(selector).hover(function(){
$(this).addClass("hover");
},function(){
$(this).removeClass("hover");
});
}
};
	$.hoverPlugin.hover(".stdtable tr");
});

$(document).ready(function () {
	$(".select2_group").select2({});	//下拉列表框
});

function onsavelink()
{
	var name = $("#name").val();
	var id = $("#id").val();
	var tlinks = $("#tlinks").val();
	var power = $("#power").val();
	var remark = $("#remark").val();
	var sort_id = $("#sort_id").val();
	var sortts= $("#sort").val();
	var isshow =$("input:radio[name='isshow']:checked").val();
	
	if(!name)
	{
		alert("带*号内容必须填写");
		return;
	}

	$.post("/management/ajaxbutton", {"op": "savevalue","valuetxt":name,"value_fied":tlinks,"id":id,"sort_id":sort_id,"remark":remark,"power":power,"sort":sortts,"isshow":isshow},
	  function(data){
			if(data ==201)
			{
				alert("菜单名称已被占用!");
				return;
			}else if(data==202)
			{
				alert("目前只支持三级目录!");
				return;
			}else{
				//显示数据
				if(id){
					document.location.href = "/management/menulist";
					return;
				}
				showgroup();
				return;
			}
	   },"json");
}

function oncechelink()
{
	$.post("/management/ajaxbutton", {"op": "cechelink"},
	  function(data){
			if(data ==201)
			{
				alert("菜单名称已被占用!");
				return;
			}else if(data==202)
			{
				alert("目前只支持三级目录!");
				return;
			}else{
				//显示数据
				if(id){
					alert('菜单更新成功');
					location.reload();
					return;
				}
				showgroup();
				return;
			}
	   },"json");
}


/******全站ajax button.
***
*** F: 表单ID
*** T： 模块ID
*****************/
function AWSsubmit(f,t)
{
	//$("#"+t).validate();
	$('#'+t).modal('hide');
	AWS.ajax_post($('#'+f));
	
}
/******全站ajax button****/
function delone(id,t)
{
	if(confirm("确定移除?"))
	{
		$.post("/product/ajaxbutton", {"op": "delone","id":id,"st":t},
		  function(data){
				if(data.txt==200)
				{
					document.location.href = data.url;
					return;
				}

				if(data.txt==201)
				{
					alert(data.text);
					return ;
				}
				
			return;
		   },"json");
	}
}
function allSelect(id) {

	var vote_arr = document.getElementsByName(id);

	for(var j = 0; j < vote_arr.length; j++)
	{
	   if(vote_arr[j].checked == false)
	   {
	      vote_arr[j].checked=true;
	   }else{
		  vote_arr[j].checked=false;
	   }
	   
	}
 }
/*******获取全部商品分类*****/
function getsecondcate(t)
{
	var bigclassID = $("#bigclassID").val();
	if(bigclassID)
	{
		$.post("/product/ajaxbutton", {"op": "selectcategory","sort_id":bigclassID},
		  function(data){
			
				if(data ==201)
				{
					
				}else{
					var tmp="<select name=\"secondclassID\" id=\"secondclassID\" class=\"selection\" style=\"width:200px;\" onChange=\"getthirdcate()\">";
						tmp+='<option value="">请选择</option>';
					for(var i=0;i<data.length;i++)
					{
						if(t == data[i].id)
						{
							var st = "selected";
						}else{
							var st = "";
						}
						tmp+=" <option value=\""+data[i].id+"\" "+st+">"+data[i].cate_name+"</option>";
						
					}
					tmp+=" </select>";
					$("#showsecondcate").html(tmp);
				
				}
				
			
		   },"json");	
	}
}
function getthirdcate(t,s)
{
	if(t)
	{
		var secondclassID =t;
	}else{
		var secondclassID = $("#secondclassID").val();
	}
	if(secondclassID)
	{
		$.post("/product/ajaxbutton", {"op": "selectcategory","sort_id":secondclassID},
		  function(data){
			
				if(data ==201)
				{
					
				}else{
					var tmp="<select name=\"ThreeclassID\" id=\"ThreeclassID\" class=\"selection\" style=\"width:200px;\" >";
						tmp+='<option value="">请选择</option>';
					for(var i=0;i<data.length;i++)
					{
						if(s == data[i].id)
						{
							var st = "selected";
						}else{
							var st = "";
						}
						tmp+=" <option value=\""+data[i].id+"\" "+st+">"+data[i].cate_name+"</option>";
						
					}
					tmp+=" </select>";
					$("#showthirdcate").html(tmp);
				
				}
				
			
		   },"json");	
	}
}

function openMailNoUrl(id,orderType)
{
	 window.open('/order/ajaxbutton?op=sfexpressurl&orderType='+orderType+'&id='+id+'', 'newwindow', 'width='+(window.screen.availWidth-10)+',height='+(window.screen.availHeight-30)+' , top=0, left=0, toolbar=no, menubar=no, scrollbars=auto, resizable=no, location=no, status=no')
}
function openinvoiceUrl(id,orderType)
{
	document.location.href = "/order/ajaxbutton?op=printinvoice&id="+id+"&orderType="+orderType;
}

function moreopenMailNoUrl(t,orderType)	//orderType 1、顺丰 2、UPS
{
	var str = selectallpro();
	if(str !=false)
	{
		if(t==1)	//打印标签
			openMailNoUrl(str,orderType);
		if(t==2)	//打印发票
			openinvoiceUrl(str,orderType);
	}
/*
	var vote_arr = document.getElementsByName("ppid[]");
	var idarr = new Array();
	var i=0;
	var str="";
	for(var j = 0; j < vote_arr.length; j++)
	{
	   if(vote_arr[j].checked == true)
	   {
	       idarr[i] = vote_arr[j].value;
		   str += vote_arr[j].value+",";
		   i++;
	   }
	   
	}
	if(i<=0){
		alert("未选中数据");
	}else{
		if(t==1) 
			openMailNoUrl(str);
		if(t==2) 
			openinvoiceUrl(str);
		
	}*/
}

/*************
***
***	公用全选按钮
********/
function selectallpro(){
	var vote_arr = document.getElementsByName("ppid[]");
	var idarr = new Array();
	var i=0;
	var str="";
	for(var j = 0; j < vote_arr.length; j++){
	   if(vote_arr[j].checked == true){
	       idarr[i] = vote_arr[j].value;
		   str += vote_arr[j].value+",";
		   i++;
	   }
	}
	if(i<=0){
		alert("未选中数据");
		return false;
	}else{
		return str;
		
	}
}




function Dodistribution()
{
	var str = selectallpro();
	if(str !=false)
	{
		$.post("/datareport/ajaxbutton", {"op": "dodistribution","str":str},
		  function(data){
			
				if(data==200)
				{
					document.location.href = '/order/sfexpress';
				}
			
		   },"json");	
	}
/*
	var vote_arr = document.getElementsByName("ppid[]");
	var idarr = new Array();
	var i=0;
	var str="";
	for(var j = 0; j < vote_arr.length; j++)
	{
	   if(vote_arr[j].checked == true)
	   {
	       idarr[i] = vote_arr[j].value;
		   str += vote_arr[j].value+",";
		   i++;
	   }
	   
	}
	if(i<=0){
		alert("未选中数据");
	}else{
		$.post("/datareport/ajaxbutton", {"op": "dodistribution","str":str},
		  function(data){
			
				if(data==200)
				{
					document.location.href = '/order/sfexpress';
				}
			
		   },"json");	
	}*/
}

/********增加多行上传附件*******************/
var totalnum = 1;
function showinput(t)
{
	var inputn = document.getElementById(t);
	var str=inputn.innerHTML;
	var num=1;
	for(var i=1;i<=num;i++){
		totalnum=totalnum+i;
		str += "<tr id=las"+totalnum+">";
		str+="<td>上传：</td>";
        str+="<td><input type=\"file\" name=\"userfile["+totalnum+"]\" id=\"userfile"+totalnum+"\"  style=\"height:25px;\"/>&nbsp;&nbsp;<a href=javascript:void(0) onclick=delfileinput("+totalnum+")><span style=\"padding:5px 0 0\" class=\"c9\">移除</span></a></td>";
        str+="</tr>";
	}
	$("#"+t).html(str);
	
}
function delfileinput(id)
{
	if(confirm("确定移除？"))
	{
		$("#las"+id).remove();
	}
}

function onsetoneshop(id)
{
	var vote_arr = $("#"+id);
	var idarr = new Array();
	var oneid="";
	for(var j = 0; j < vote_arr.length; j++)
	{
	  var oneid = vote_arr[j].value;
	   
	}
	if(oneid=="")
	{
		alert("请先对应第一个店铺！");
	}else{
		$("select#"+id).val(oneid);
	}

}
 function iscsv()
{
	$("#if_csv").val(1);
	$("#search").submit();
}


function closetips(e,m,o)
{
	var r = /\[(.+?)\]/g;
	var newr = m.match(r);
	var newstr = newr[0];
	var ID = newstr.substring(newstr.indexOf("[")+1,newstr.indexOf("]"));
	if(ID>0)
	{
		$.post("/doit/ajaxbutton", {"op": "domessage","ID":ID},
		  function(data){
				if(data)
				{
					if(data.url)
					{
						//document.location.href =data.url;
					}
				}
			
		   },"json");	
	}
	
}

function cancel(redio){
   var checkedstr = document.getElementsByName(redio);
   for(var i = 0 ;i<checkedstr.length; i++){
      checkedstr[i].checked = false;
   }
}


function trim(str){ //删除左右两端的空格 
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
} 


/****商品信息成本价修改时需要填写备注信息**********/

function changpricememo(goods_id,g_costprice)
{
	$("#pricememo").html('');
	var newcosprice = $("#costprice").val();

	if(g_costprice != newcosprice)	//修改了价格请填写备注信息
	{
		$("#pricememo").html("修改成本价原因：<input type=\"text\" name=\"pricememo\" id=\"pricememo\" class=\"width200\" required> ");
	}
	
}
function changbulkpricememo(goods_id,bulkprice)
{
	$("#bulkpricepricememo").html('');
	var newbulkprice = $("#bulkprice").val();
	if(bulkprice != newbulkprice)	//修改了价格请填写备注信息
	{
		$("#bulkpricepricememo").html("修改关联价原因：<input type=\"text\" name=\"bulkpricepricememo\" id=\"bulkpricepricememo\" class=\"width200\" required> ");
	}
	
}

function getShopList(){	
	//var selectval=$("#shopname").val();
	var selectval='';
	var fbatype=$("#fbastate").val();
	
	$.post("/report/ajaxbutton",{"op": "getShopList",'selected':selectval,'fbatype':fbatype},function(data){														
		$("#shop_box").html(data);
		$("#ajax_box").show();
	},"text");
}

function closeShowBox(){
	$("#ajax_box").hide();	
}


/*******排序************/
function paixu(field,orderby)
{
	$("#byt").val(field);
	$("#orderby").val(orderby);
	$("#search").submit();
}